import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from '@angular/core';
declare var QRCode: any;
declare var $: any;
@Component({
  selector: 'canvasCode-root',
  templateUrl: './canvasCode.component.html',
  styleUrls: ['./canvasCode.component.css']
})
export class canvasCodeComponent implements OnInit {
  @ViewChild('qrcodedom') qrcodedom: any;
  @Output() onCloseCode = new EventEmitter<Event>();
  @Output() onCodeLG = new EventEmitter<Event>();
  @Output() onCodeSM = new EventEmitter<Event>();
  @Input() CanvasGroupGuid: any;
  @Input() codemsg: any;
  @Input() trainMsg: any;
  tip = '点击二维码放大';
  ngOnInit() {
    this.code('290')
  }
  enlarge() {
    if (this.codemsg.type == "sm") {
      this.code('500')
      this.tip = '点击二维码缩小';
      this.onCodeLG.emit(this.codemsg)
    }
    if (this.codemsg.type == "lg") {
      this.code('290')
      this.tip = '点击二维码放大';
      this.onCodeSM.emit(this.codemsg)
    }
  }
  code(width) {
    $('.Code').html('')
    new QRCode(this.qrcodedom.nativeElement, {
      width: width,
      height: width
    }).makeCode(`http://clientcanvasserver.lessonplan.cn/check/${this.CanvasGroupGuid}`);
  }
  closecode() {
    this.onCloseCode.emit()
  }
}
